class Renderer {
  Graphics graphics;
  List<mat4> transformStack;
  GPUProgram program;
  
  Renderer(Graphics graphics) {
    this.graphics = graphics;
    this.transformStack = new List<mat4>();
    this.transformStack.add(new mat4.identity());
    this.program = new GPUProgram(
      '''
attribute vec3 VPosition;
attribute vec2 VTexture1;

uniform mat4 World;
uniform mat4 Projection;

varying vec2 VaryingVTexture;

void main(void)
{
    gl_Position = Projection * World * vec4(VPosition, 1.0);
    VaryingVTexture = VTexture1;
}
      ''',
      '''
precision mediump float;

uniform sampler2D Sampler1;
varying vec2 VaryingVTexture;

void main(void)
{
    gl_FragColor = texture2D(Sampler1, VaryingVTexture);
}
      ''');
  }
  
  void pushTransform(mat4 m) {
    transformStack.add(m); 
    graphics.worldTM = transformStack.last();
  }
  
  void popTransform() {
    if (transformStack.length > 1)
      transformStack.removeLast();
    
    graphics.worldTM = transformStack.last();
  }
  
  void draw(Texture texture, num originX, num originY) {
    graphics.draw(program, texture, 0, 0, originX, originY, [0,0,31,39]);
  }
}
